<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.AdminAction"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>

<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="../images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; 系统管理&gt;&gt; 岗检标准管理&gt;&gt; 添加岗检标准
</div>

<%
{
	Long postcheckID = 0l;
	Long postcheckPatternID = 0L;
	Long postcheckContentID = 0L;
	try{
		postcheckID = Long.parseLong((String) request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_ID));
		postcheckPatternID = Long.parseLong((String) request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_PATTERN_ID));
		postcheckContentID = Long.parseLong((String) request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_CONTENT_ID));
	} catch (Exception e) {
		%>
		<script type="text/javascript">
			loadPageSection('<%=request.getContextPath()%>'+'/admin/postcheck.jsp', 'mainContentDiv', {}, true);
		</script>
		<%
	}
	
	String postcheckName = Util.isoToUTF8((String)request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_NAME));
	String postcheckPattern = Util.isoToUTF8((String)request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_PATTERN));
	String postcheckContent = Util.isoToUTF8((String)request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_CONTENT));
%>
<div class="tt">添加岗检标准</div>
<div class="content">
	<p>岗检：<%=postcheckName %></p>
	<br/>
	<br/>	
	
	
	<table border="1" width="99%" cellpadding="0" cellspacing="1" style="align:center;">
		<tr height="35px">
			<td style="width:100px;padding-left:5px;">
				检查方式：
			</td>
			<td style="padding-left:5px;">
				<%=postcheckPattern.trim() %>
			</td>		
		</tr>
		<tr height="35px">
			<td style="padding-left:5px;">
				工作内容：
			</td>
			<td style="padding-left:5px;">
				<%=postcheckContent.trim() %>
			</td>		
		</tr>
		<tr height="35px">
			<td style="padding-left:5px;">
				工作标准与要求：
			</td>
			<td style="padding-left:5px;padding-top:5px;padding-bottom:5px;">
				<textarea id="inputStandard" rows="5" cols="50"></textarea>
			</td>		
		</tr>
		<tr height="55px">
			<td style="padding-left:5px;">
				工作标准来源：
			</td>
			<td style="padding-left:5px;">
				<span id="sourceSpan">
					<input type="hidden" id="inputSourceIDs" name="inputSourceIDs" value=""></input>
					<div id="divSourceNames"></div>
				</span>
				<%@include file="postcheck_select/source_select_section.jsp" %>
				<input type="button" onclick="addPostcheckSource()" value="添加到标准来源"/>
			</td>		
		</tr>
		<tr height="35px">
			<td style="padding-left:5px;">
				扣分标准：
			</td>
			<td style="padding-left:5px;">
				<input type="text" id="inputGradeStandard" name="inputGradeStandard"></input>
			</td>		
		</tr>
		<tr height="35px">
			<td style="padding-left:5px;">
				检查频次：
			</td>
			<td style="padding-left:5px;">
				<input type="text" id="inputCheckFrequency" name="inputCheckFrequency"></input>
			</td>		
		</tr>	
		<tr>
			<td colspan="2" class="td1" align="center">
				<input type="button" value="添加" onclick="addPostcheckStandard()" />&nbsp;&nbsp;
				<input type="button" value="返回" onclick="goBack()" />
			</td>
		</tr>	
	</table>
</div>
<script type="text/javascript">
function selectPostcheckSource(){
	return;
}

function addPostcheckSource(){
	var currentIDs = $("#inputSourceIDs").val();
	var currentNames = $("#divSourceNames").html();
	var selectedID = $("select[@id='postcheckSource'] option[@selected]").val();
	var selectedName = $("select[@id='postcheckSource'] option[@selected]").text();
	$("#inputSourceIDs").val(currentIDs + ',' + selectedID);
	$("#divSourceNames").html(currentNames + '<br>~' + selectedName+'&nbsp;&nbsp;<a href="javascript:deleteSelectSource('+selectedID+')">删除</a>');
	return;
}

function deleteSelectSource(sourceId){
	var currentIDs = $("#inputSourceIDs").val();
	var currentNames = $("#divSourceNames").html();
	var IDs = currentIDs.split(",");
	var names = currentNames.split("~");
	
	var idsAfterDelete = '';
	var namesAfterDelete = '';
	var deleted = 0;
	for(var i = 1; i<IDs.length; i++ ){
		if(IDs[i] == sourceId && deleted == 0){
			deleted = 1;
		} else {
			idsAfterDelete = idsAfterDelete + ',' + IDs[i];
			namesAfterDelete = namesAfterDelete + '~' + names[i];
		}
	}
	
	$("#inputSourceIDs").val(idsAfterDelete);
	$("#divSourceNames").html(namesAfterDelete);
	return;
}

function addPostcheckStandard(){
	var postcheckStandard = $("#inputStandard").val();
	var postcheckSources = $("#inputSourceIDs").val();
	var postcheckGradeStandard = $("#inputGradeStandard").val();
	var postcheckCheckFrequency = $("#inputCheckFrequency").val();
	
	if(postcheckStandard == null || postcheckStandard == '' || postcheckStandard == 'undefined') {
		$.dialog.alert('请输入工作标准与要求');
		return;
	}

	openWaitingDialog('waitingDialog');
	$.ajax({
		type:'post',
		url:'add_postcheck_standard_process.jsp',
		data:{			
			postcheckID: <%=postcheckID%>, 
			postcheckPatternID: <%=postcheckPatternID%>,
			postcheckContentID: <%=postcheckContentID%>,
			postcheckStandard: postcheckStandard,
			postcheckSources: postcheckSources,
			postcheckGradeStandard: postcheckGradeStandard,
			postcheckCheckFrequency: postcheckCheckFrequency
		},
		contentType: 'application/x-www-form-urlencoded; charset=utf-8',
		success:function(data,state,xmlhttp){
			var obj = null;
			try {
				obj = eval('(' + data + ')');
			} catch (e) {
			}
			if (typeof(obj.isSuccess) != 'undefined') {
				closeWaitingDialog('waitingDialog');
				if (obj.isSuccess == 'true') {					
					$.dialog('添加成功！', function() { goBack();});					
				} else {
					$.dialog.alert(obj.error);
				}
			}
		}
	});		
}

function goBack(){
	loadPageSection('postcheck.jsp', 'mainContentDiv', {
		postcheckID: <%=postcheckID%>, 
		postcheckPatternID: <%=postcheckPatternID%>,
		postcheckContentID: <%=postcheckContentID%>
		}, false);
}
</script>
<%
}
%>